package com.wdm.sms.commonutil.config.exception;

import com.wdm.sms.commonutil.enums.ResponseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author: wudaiming
 * @date: 2023/3/13
 * @description: 自定义运行时异常
 * @version: 1.0
 */


@Data
@ApiModel(value = "自定义全局异常类")
public class MyException extends RuntimeException{
    @ApiModelProperty(value = "异常状态码")
    private final Integer code;
    /**
     * 通过状态码和异常信息创建异常对象
     * @param code
     * @param message
     */
    public MyException(Integer code,String message) {
        super(message);
        this.code = code;
    }

    /**
     * 接受枚举类型对象
     * @param responseEnum
     */
    public MyException(ResponseEnum responseEnum){
        super(responseEnum.getMessage());
        this.code = responseEnum.getCode();
    }
}